<template>
  <div class="addResource">
    <div
      class="dialog animated"
      :class="open? 'fadeIn':'fadeOut'"
      v-show="show"
      :style="{visibility: (visible?'visible':'hidden')}"
    >
      <div class="panel animated" :class="open? 'zoomIn':''">
        <div class="title">
          新建目录
          <div class="close" @click="cancel()"></div>
        </div>
        <div>
          <el-form label-width="200px">
            <el-form-item label="目录名称" :rules="[
      { required: true, message: ''}]">
              <el-input
                style="width:60%"
                clearable
                v-model="folderObject.name"
                placeholder="请输入目录名称"
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="btn_div">
          <div class="btn_sure" @click="sure()">确 认</div>
          <div class="btn_cancel" @click="cancel()">取 消</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
var vm, user;
export default {
  data: function() {
    return {
      show: false,
      open: false,
      visible: false,
      folderObject: {
        appId: "vxiao",
        createUserId: "",
        createUserName: "",
        name: "",
        parentId: "",
        _wait: ""
      }
    };
  },
  methods: {
    init: function(parentId) {
      vm.show = true;
      setTimeout(function() {
        vm.open = true;
        vm.visible = true;
      }, 11);
      //初始化数据
      vm.folderObject.parentId = parentId;
      vm.folderObject.name = "";
    },
    sure: function() {
      if (!tool.judge("courseName", this.folderObject.name)) {
        this.$message.warning("请输入有效的文件夹名称");
        return;
      }
      vm.folderObject.createUserId = user.userId;
      vm.folderObject.createUserName = user.nickName;
      vm.folderObject.objectId = user.orgId;
      api.folderAdd(vm.folderObject).then(function(result) {
        tool.message({ message: "添加成功", type: "success" });
        vm.$emit("callback");
        vm.cancel();
      });
    },
    cancel: function() {
      //隐藏弹窗
      vm.open = false;
      setTimeout(function() {
        vm.show = false;
        vm.visible = false;
      }, 500);
    }
  },
  created: function() {
    vm = this;
    user = tool.getItem(lsKey.user, true);
  }
};
</script>
<style lang="scss">
.addResource {
  .el-form-item__label {
    font-size: 0.16rem;
    color: #666666;
  }
  .el-checkbox__label {
    font-size: 0.16rem;
    color: #666666;
  }
}
</style>
<style scoped src="@/style/module/dialog.css"></style>
<style scoped>
.panel {
  padding: 0.2rem;
  width: 8rem;
}
</style>